#!/usr/bin/env python
# -*- coding:utf8 -*-
# uncompyle6 version 2.15.1
# Python bytecode 2.7 (62211)
# Decompiled from: Python 2.7.10 (default, Jul  1 2017, 13:36:56) 
# [GCC 4.4.6 20110731 (Red Hat 4.4.6-4)]
# Embedded file name: ./paas/api/views.py
# Compiled at: 2017-11-16 15:44:28
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from account.decorators import login_exempt
from api.decorators import esb_required
from api.utils import InnerFeedback
from app.models import App

@csrf_exempt
@login_exempt
@esb_required()
def get_app_info(request):
    """
    @api {GET} /paas/api/app_info/ get_app_info
    @apiName get_app_info
    @apiGroup BK_PAAS
    @apiVersion 1.0.0
    @apiDescription 获取应用信息[支持批量获取]
    @apiParam (GET参数) {String} target_app_code 应用ID，多个target_app_code以英文分号分隔，target_app_code为空则表示所有应用
    @apiParamExample {json} 接口参数示例:
        {
            "target_app_code": "test1;test2",
        }
    @apiSuccessExample {json} Success-Response
        HTTP/1.1 200 OK
        {
            "result": true,
            "code": '00',
            "message": "SUCCESS",
            "data": [
                {
                    'app_code': 'test1',
                    'app_name': '测试1',
                },
                {
                    'app_code': 'test2',
                    'app_name': '测试2'
                }
            ]
        }
    """
    feedback = InnerFeedback()
    app_code = request.GET.get('target_app_code')
    all_app = App.objects.all()
    if app_code:
        app_code_list = app_code.split(';')
        all_app = all_app.filter(code__in=app_code_list)
    all_app = all_app.values('code', 'name').order_by('-created_date')
    app_list = [ {'app_code': i['code'],'app_name': i['name']} for i in all_app
               ]
    feedback['data'] = app_list
    return JsonResponse(feedback)
